package com.amsp.oa.oademo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.amsp.oa.oademo.common.Result;
import com.amsp.oa.oademo.entity.EmployeeFile;
import com.amsp.oa.oademo.service.EmployeeFileService;
import com.amsp.oa.oademo.vo.EmployeeFileVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "员工档案管理")
@RestController
@RequestMapping("/api/employee/file")
@CrossOrigin
public class EmployeeFileController {

    @Resource
    private EmployeeFileService employeeFileService;

    @ApiOperation("分页查询员工档案")
    @GetMapping("/page")
    public Result<IPage<EmployeeFile>> getPage(
            @ApiParam("当前页码") @RequestParam(defaultValue = "1") Integer current,
            @ApiParam("每页大小") @RequestParam(defaultValue = "10") Integer size,
            @ApiParam("搜索关键字") @RequestParam(required = false) String keyword) {
        return Result.ok(employeeFileService.getPage(current, size, keyword));
    }

    @ApiOperation("获取员工档案详情")
    @GetMapping("/{id}")
    public Result<EmployeeFileVO> getDetail(@PathVariable Long id) {
        return Result.ok(employeeFileService.getDetail(id));
    }

    @ApiOperation("保存或更新员工档案")
    @PostMapping("/save")
    public Result<?> saveOrUpdate(@RequestBody EmployeeFileVO vo) {
        employeeFileService.saveOrUpdateEmployee(vo);
        return Result.ok();
    }

    @ApiOperation("批量删除员工档案")
    @DeleteMapping("/batch")
    public Result<?> removeBatch(@RequestBody Long[] ids) {
        employeeFileService.removeBatch(ids);
        return Result.ok();
    }
}